package com.zrgg.futuwen.app;

import android.app.Activity;
import android.app.Application;

import com.umeng.socialize.Config;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;
import com.zrgg.futuwen.utils.ImgSelectConfig;
import com.zrgg.futuwen.utils.Logger;
import com.zrgg.futuwen.wxapi.WChatConstants;

import java.util.Stack;

public class MyApp extends Application {

    private static MyApp instance;
    public Stack<Activity> allActivities;

    public static MyApp getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        //初始化图片选择器
        ImgSelectConfig.init(this);

        if (Logger.isDebug) Config.DEBUG = Logger.isDebug;
        //TODO 此处替换正确的key
        PlatformConfig.setWeixin(WChatConstants.APP_ID, WChatConstants.AppSecret);
        PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba");
        PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad", "http://sns.whalecloud.com");
        UMShareAPI.get(this);
    }


    public void addActivity(Activity act) {
        if (allActivities == null) {
            allActivities = new Stack<>();
        }
        allActivities.add(act);
    }

    public void removeActivity(Activity act) {
        if (allActivities != null) {
            allActivities.remove(act);
        }
    }

    public Activity getCurrActivity() {
        Activity activity = null;

        if (!allActivities.isEmpty()) {

            Activity a = allActivities.lastElement();
            if (a instanceof Activity) {
                return (Activity) a;
            }

        }
        return null;
    }


    public void exitAllAcrivity() {
        if (allActivities != null) {
            synchronized (allActivities) {
                for (Activity act : allActivities) {
                    act.finish();
                }
            }
        }

    }


}
